﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;
namespace CungMuaC5.Account_Admin
{
    public partial class DanhSachTinKM : System.Web.UI.Page
    {
        private BUS_KhuyenMai bus = new BUS_KhuyenMai();
        int MaKM = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                MaKM = int.Parse(Request.QueryString["ma"].ToString());
            }
            catch (Exception ex) { }
            GetDSTinKM();
            if (MaKM != 0)
            {
                Update();
            }
            //if (MaKM != 0)
              //  Update();
            
        }
        public void GetDSTinKM()
        {
            List<DTO_KM> danhsachTinKM;
            danhsachTinKM = bus.GetDSTinKM();
            if (danhsachTinKM.Count > 0)
            {
                Label15.Text = "Kết Quả: " + danhsachTinKM.Count.ToString();
                GridView2.DataSource = danhsachTinKM;
                GridView2.DataBind();
            }
            else
            {
                Label15.Text = "Không Tìm Thấy!";
            }
        }

        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {
            int i = 0;
            i = DropDownList1.SelectedIndex + 1;
            List<DTO_KM> danhsachTinKM = new List<DTO_KM>();
            danhsachTinKM = bus.GetDSTinKMTheoLoai(i);
            if (danhsachTinKM.Count > 0)
            {
                Label15.Text = "Kết Quả: " + danhsachTinKM.Count.ToString();
                GridView2.DataSource = danhsachTinKM;
                GridView2.DataBind();
            }
            else
            {
                Label15.Text = "Không Tìm Thấy!";
            }
        }
        private void Update()
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript'>alert('Thực sự muốn xóa Tin KM này ?');</script>");
            bool i = bus.deleteTinKM(MaKM);
            
        }
        protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript'>alert('Thực sự muốn xóa Tin KM này ?');</script>");
            bool i = bus.deleteTinKM(MaKM);
            string url = "~/Account_Admin/QuanLyTinKM/QuanLiTinKM.aspx";
            Response.Redirect(url);
        }
        protected void GridView2_PageIndexChanged(object sender, EventArgs e)
        {

        }
        protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            Update();
        }

    }
}